package com.gene.controller;

import com.gene.pojo.UserReport;
import com.gene.service.IUserReportService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户基因报告详情
 */
@Controller
@RequestMapping("/gene-safe/userReport")
public class UserReportController {
    @Autowired
    private IUserReportService userReportService;

    /**
     * 查询    userId为查询条件
     * @param userReport
     * @return
     */
    @RequestMapping(value="/query")
    @ResponseBody
    public ResultData query(UserReport userReport){
        ResultData result=new ResultData();
        List<UserReport> list=userReportService.query(userReport);
        if(list.size()>0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }

        return result;
    }

    /**
     * 查询    userId为查询条件
     * @param userReport
     * @return
     */
    @RequestMapping(value="/selectId")
    @ResponseBody
    public ResultData selectId(UserReport userReport){
        ResultData result=new ResultData();
        UserReport u = userReportService.selectId(userReport);
        if(null != u){
            result.setData(u);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }

        return result;
    }



    /**
     * 新增
     * @param userReport
     * @return
     */
    @RequestMapping(value="/add")
    @ResponseBody
    public ResultData add(UserReport userReport){
        ResultData result =new ResultData();
        boolean a=userReportService.add(userReport);
        if(a){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;
    }

    /**
     * 修改
     *
     * @param userReport
     * @return
     */
    @RequestMapping(value="/edit")
    @ResponseBody
    public ResultData edit(UserReport userReport){
        ResultData result =new ResultData();
        boolean a=userReportService.edit(userReport);
        if(a){
            result.setStatus("1");
            result.setMsg("修改成功...");
        }else{
            result.setStatus("0");
            result.setMsg("修改失败！");
        }
        return result;
    }

    /**
     * 删除
     * @param userReport
     * @return
     */
    @RequestMapping(value="/delete")
    @ResponseBody
    public ResultData delete(UserReport userReport) {
        ResultData result = new ResultData();
        boolean a=userReportService.delete(userReport);
        if(a){
            result.setStatus("1");
            result.setMsg("删除成功...");
        }else{
            result.setStatus("0");
            result.setMsg("删除失败！");
        }
        return result;
    }

}
